package zhangxin.first;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 测试圆形
        System.out.println("=== 圆形计算 ===");
        System.out.print("请输入圆的半径: ");
        double radius = scanner.nextDouble();

        Circle circle = new Circle(radius);
        System.out.println("圆的周长: " + String.format("%.2f", circle.getPerimeter()));
        System.out.println("圆的面积: " + String.format("%.2f", circle.getArea()));

        // 测试GeometricObject方法
        System.out.println("当前颜色: " + circle.getColor());
        circle.setColor("red");
        System.out.println("设置后颜色: " + circle.getColor());

        System.out.println("当前filled属性: " + circle.isFilled());
        circle.setFilled(true);
        System.out.println("设置后filled属性: " + circle.isFilled());

        System.out.println("圆形信息: " + circle.toString());

        System.out.println("\n=== 长方形计算 ===");
        System.out.print("请输入长方形的宽: ");
        double width = scanner.nextDouble();
        System.out.print("请输入长方形的高: ");
        double height = scanner.nextDouble();

        Rectangle rectangle = new Rectangle(width, height);
        System.out.println("长方形的面积: " + String.format("%.2f", rectangle.getArea()));

        // 测试GeometricObject方法
        System.out.println("当前颜色: " + rectangle.getColor());
        rectangle.setColor("blue");
        System.out.println("设置后颜色: " + rectangle.getColor());

        System.out.println("当前filled属性: " + rectangle.isFilled());
        rectangle.setFilled(false);
        System.out.println("设置后filled属性: " + rectangle.isFilled());

        System.out.println("长方形信息: " + rectangle.toString());

        scanner.close();
    }
}

// 抽象几何图形基类
abstract class GeometricObject {
    private String color = "white";
    private boolean filled = false;

    public GeometricObject() {
    }

    public GeometricObject(String color, boolean filled) {
        this.color = color;
        this.filled = filled;
    }

    // 返回颜色
    public String getColor() {
        return color;
    }

    // 设置新的颜色
    public void setColor(String color) {
        this.color = color;
    }

    // 返回filled属性
    public boolean isFilled() {
        return filled;
    }

    // 设置新的filled属性
    public void setFilled(boolean filled) {
        this.filled = filled;
    }

    // 返回对象的字符串表述
    @Override
    public String toString() {
        return "GeometricObject[color=" + color + ", filled=" + filled + "]";
    }

    // 抽象方法 - 计算面积
    public abstract double getArea();

    // 抽象方法 - 计算周长
    public abstract double getPerimeter();
}

// 圆类
class Circle extends GeometricObject {
    private double radius;

    public Circle() {
        super();
        this.radius = 1.0;
    }


    public Circle(double radius) {
        super();
        this.radius = radius;
    }


    public Circle(double radius, String color, boolean filled) {
        super(color, filled);
        this.radius = radius;
    }

    // 获取半径
    public double getRadius() {
        return radius;
    }

    // 设置半径
    public void setRadius(double radius) {
        this.radius = radius;
    }

    // 计算面积
    @Override
    public double getArea() {
        return Math.PI * radius * radius;
    }

    // 计算周长
    @Override
    public double getPerimeter() {
        return 2 * Math.PI * radius;
    }

    // 返回圆的字符串表述
    @Override
    public String toString() {
        return "Circle[radius=" + radius + ", " + super.toString() + "]";
    }
}

// 长方形类
class Rectangle extends GeometricObject {
    private double width;
    private double height;


    public Rectangle() {
        super();
        this.width = 1.0;
        this.height = 1.0;
    }


    public Rectangle(double width, double height) {
        super();
        this.width = width;
        this.height = height;
    }


    public Rectangle(double width, double height, String color, boolean filled) {
        super(color, filled);
        this.width = width;
        this.height = height;
    }

    // 获取宽度
    public double getWidth() {
        return width;
    }

    // 设置宽度
    public void setWidth(double width) {
        this.width = width;
    }

    // 获取高度
    public double getHeight() {
        return height;
    }

    // 设置高度
    public void setHeight(double height) {
        this.height = height;
    }

    // 计算面积
    @Override
    public double getArea() {
        return width * height;
    }

    // 计算周长
    @Override
    public double getPerimeter() {
        return 2 * (width + height);
    }

    // 返回长方形的字符串表述
    @Override
    public String toString() {
        return "Rectangle[width=" + width + ", height=" + height + ", " + super.toString() + "]";
    }
}